package com.gosophia.reportData.action;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.flowFormManagement.dto.FlowFormDTO;
import com.gosophia.flowFormManagement.dto.FormInstanceDTO;
import com.gosophia.flowFormManagement.ws.FormInstanceWebService;
import com.gosophia.reportData.dto.ApprovalReportJobDTO;
import com.gosophia.reportData.ws.LaunchReportWebService;
import com.gosophia.reportData.ws.ReportJobWebService;
import com.opensymphony.xwork2.Action;

/**
 * 审核操作
 * 
 * @author tianchunyu
 * 
 */
@Controller
@Scope("prototype")
public class ApprovalAction extends BaseSupportAction{

	/**
     * 
     */
	private static final long serialVersionUID = 1L;

	private Long jobId;
	
	private ApprovalReportJobDTO approvalReportJobDto;
	
	private FormInstanceDTO formInstanceDTO;
	
	private Map<String,Object> newDataInstance;

	@Autowired
	private LaunchReportWebService launchReportWebService;
	
	@Autowired
	private ReportJobWebService reportJobWebService;
	
	@Autowired
	private FormInstanceWebService formInstanceWebService;

	private String fromFlag;
	@Override
	public String _execute() throws Exception {
		approvalReportJobDto = launchReportWebService.findApprovalReportJobDto(jobId);
		String mode = approvalReportJobDto.getReportJobDto().getLaunchReportJobDto().getReportMethod();
		if(approvalReportJobDto.isFirstApp()){
			if ("F".equals(mode)) {
                    return "attachCheck";
				
			} else {
				FlowFormDTO flowFormDTO = approvalReportJobDto.getReportJobDto().getLaunchReportJobDto().getFlowFormDto();
				if (flowFormDTO.getModel().equals('F')) {
//					formInstanceDTO = formInstanceWebService
//							.findFormInstanceById(approvalReportJobDto.getReportJobDto().getFormInstanceId());
//					Map<Long, Object> dataInstance = formInstanceDTO
//							.getInstanceData();
//					newDataInstance = reportJobWebService
//							.findFlowFormData(dataInstance);
	                    return "flowFormCheckForm";
					
				} else if (flowFormDTO.getModel().equals('E')) {
                        return "excelCheckForm";
				}
			}
		}else{
			if ("F".equals(mode)) {
                    return "attachCheck_";
			} else {
				FlowFormDTO flowFormDTO = approvalReportJobDto.getReportJobDto().getLaunchReportJobDto().getFlowFormDto();
				if (flowFormDTO.getModel().equals('F')) {
//					formInstanceDTO = formInstanceWebService
//							.findFormInstanceById(approvalReportJobDto.getReportJobDto().getFormInstanceId());
//					Map<Long, Object> dataInstance = formInstanceDTO
//							.getInstanceData();
//					newDataInstance = reportJobWebService
//							.findFlowFormData(dataInstance);
		                 return "flowFormCheckForm_";
				} else if (flowFormDTO.getModel().equals('E')) {
                        return "excelCheckForm_";
				}
			}
		}
		return Action.ERROR;
	}

	public Long getJobId() {
		return jobId;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public ApprovalReportJobDTO getApprovalReportJobDto() {
		return approvalReportJobDto;
	}

	public void setApprovalReportJobDto(ApprovalReportJobDTO approvalReportJobDto) {
		this.approvalReportJobDto = approvalReportJobDto;
	}

	public FormInstanceDTO getFormInstanceDTO() {
		return formInstanceDTO;
	}

	public void setFormInstanceDTO(FormInstanceDTO formInstanceDTO) {
		this.formInstanceDTO = formInstanceDTO;
	}

	public Map<String, Object> getNewDataInstance() {
		return newDataInstance;
	}

	public void setNewDataInstance(Map<String, Object> newDataInstance) {
		this.newDataInstance = newDataInstance;
	}

    public String getFromFlag() {
        return fromFlag;
    }

    public void setFromFlag(String fromFlag) {
        this.fromFlag = fromFlag;
    }
	
}
